package com.training.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class SecUserDetails implements UserDetails, Serializable {

	//private static final long serialVersionUID = 1201392234549297485L;
	private long id;
	private String password;
	private String username;
	private GrantedAuthority[] authorities = null;

	public SecUserDetails() {}
	public SecUserDetails(int id, String username, String password,
			GrantedAuthority[] authorities) {
		this.id = id;
		this.password = password;
		this.username = username;
		this.authorities = authorities;
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		Collection<GrantedAuthority> auth = new ArrayList<GrantedAuthority>();
		for (int i = 0; i < authorities.length; i++) {
			auth.add(authorities[i]);
		}
		return auth;
	}

	public long getId() { return this.id; }

	public void setId(long id) { this.id = id; }

	@Override
	public String getPassword() { return this.password; }

	@Override
	public String getUsername() { return this.username; }

	@Override
	public boolean isAccountNonExpired() { return true; }

	@Override
	public boolean isAccountNonLocked() { return true; }

	@Override
	public boolean isCredentialsNonExpired() { return true; }

	@Override
	public boolean isEnabled() { return true; }

}
